<template>
    <div class="container">
        <div class="title">会员充值概况</div>
        <div class="item">
            <div class="number" :class="{ small: isSmallFont }">¥{{ formattedData.today }}</div>
            <div class="label">今日充值</div>
        </div>
        <div class="item">
            <div class="number" :class="{ small: isSmallFont }">¥{{ formattedData.yesterday }}</div>
            <div class="label">昨日充值</div>
        </div>
        <div class="item">
            <div class="number" :class="{ small: isSmallFont }">¥{{ formattedData.total }}</div>
            <div class="label">总金额</div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'TopupOverview',
    props: {
        topupOverviewData: {
            type: Object,
            default: () => ({
                today: 0,
                yesterday: 0,
                total: 0
            })
        }
    },
    computed: {
        formattedData() {
            const formatNumber = (num) => {
                if (num >= 1_000_000) return (num / 1_000_000).toFixed(1) + 'M';
                if (num >= 1_000) return (num / 1_000).toFixed(1) + 'k';
                return num.toString();
            };

            return {
                today: formatNumber(this.topupOverviewData.today),
                yesterday: formatNumber(this.topupOverviewData.yesterday),
                total: formatNumber(this.topupOverviewData.total)
            };
        },
        isSmallFont() {
            const { today, yesterday, total } = this.formattedData;
    
            return (
                today.toString().length > 5 ||
                yesterday.toString().length > 5 ||
                total.toString().length > 5
            );
        }
    }
};
</script>

<style scoped>
.container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 60px;
    background-color: transparent;
    padding: 10px 0;
}

.title {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 24px;
    color: #36C4FF;
    font-family: 'Orbitron', sans-serif;
    font-weight: bold;
}

.item {
    text-align: center;
}

.number {
    font-size: 36px;
    font-weight: bold;
    color: #fff;
    margin-bottom: 4px;
    font-family: 'Orbitron', sans-serif;
    z-index: 10;
    transition: font-size 0.3s ease;
}

.number.small {
    font-size: 24px;
}

.label {
    font-size: 24px;
    color: #ccc;
    font-family: 'Arial', sans-serif;
}
</style>
